package com.itwenke.springbootdemo.redismultiple.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(path = {"api/test"})
public class TestController {

    @Resource
    private RedisTemplate<String, String> defaultRedisTemplate;

    @Resource
    private RedisTemplate<String, String> node02RedisTemplate;

    @GetMapping(path = "set")
    public void set() {
        defaultRedisTemplate.opsForValue().set("key1", "value1");
        node02RedisTemplate.opsForValue().set("key2", "value2");
    }

    @GetMapping(path = "get")
    public void get() {
        String value1 = defaultRedisTemplate.opsForValue().get("key1");
        String value2 = node02RedisTemplate.opsForValue().get("key2");
        System.out.println("value1 = " + value1 + ", value2 = " + value2);
    }

}
